#-*- coding:utf-8 -*-
# @Author : yushen
# @Time : 2020-07-10 18:40

from common.get_cookie import *
from config.config import *
import requests

class Cheack_shop_coordinates():    #检测铺位号是否为空，无铺位号影响地图导航

    def __init__(self):#定义店铺存放列表
        self.res_list = []

    def dayunying_login(self):
        #获取大运营cookie
        url = dayunying_v8_login_host + '/ryoms/j_spring_security_check'

        header = {
            "Content-Type": "application/x-www-form-urlencoded",
            "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
        }
        data = {"j_username":dayunying_v8_name , "j_password": dayunying_v8_password, "verifyCode": ""}
        r = requests.post(url=url, headers=header, data=data, allow_redirects=False)
        cookie = requests.utils.dict_from_cookiejar(r.cookies)

        return cookie['RYST']

    def shop_list(self,url):
        #获取店铺结果
        url = url + '/ryoms/shop/searchShop'
        header = {
            'Content - Type': 'application / json;charset = UTF - 8',
            'Cookie':dayunying_login(),
            'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
        }
        payload = {"currpage":1,"pageSize":200,"paramsJson":"{\"zoneId\":\"521f07c16038b51301000001\"}"}

        response = requests.post(url,headers=header,json=payload)
        return response.json()

    def shop_name(self):
        #存放店铺坐标
        shop_json = self.shop_list('http://manage.w.rongyi.com')['result']['data']['dataList']
        for res in shop_json:
            name = res['name']
            shopNumber = res['position']['shopNumber']
            if '/' in shopNumber:
                self.res_list.append(name)

res = Cheack_shop_coordinates()
res.shop_name()
print('一共有如下店铺号为空，请核实如下店铺：{}'.format(res.res_list))